/*
 *   Copyright (C) 2007 by Andrzej Oczkowicz
 *   andrew_lz@poczta.fm
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 *   KMediaCatalog :)
 *
 */

#ifndef _KMODULE_H_
#define _KMODULE_H_

#include <QObject>
#include <QFileInfo>
#include <QPixmap>
#include <QIcon>

#define KMODULE_INIT_SYMBOL "kModuleInit"
#define KMODULE_EXIT_SYMBOL "kModuleExit"

class kVersion;
class kPlugin;
class kInputPlugin;
class kInputArchive;
class kModule;

typedef enum kDetectType{
  kDetectByExt  = 0x01,
  kDetectByProc = 0x02,
  kDetectByStr  = 0x04
};

typedef enum kInputType{
  kInputDesc    = 0x01,
  kInputThumb   = 0x02,
  kInputIcon    = 0x04
};

typedef struct kDetectInfo{
  kDetectType detectType;
  QString extList;
  QString detectStr;
};

typedef struct kFileInfo{
  QFileInfo *fileInfo;

};

typedef struct kImportedInfo{
  QString pluginName;
  QString * description;
  QIcon * icon;
  QPixmap * thumbnail;
};

typedef struct kBasicFileInfo{
  kImportedInfo import;
  QString name;
  int size;
};

typedef struct kDescStruct{
  int MaxDescLen;

};

typedef QList<kBasicFileInfo> kQuasiArchiveContent;

typedef struct kInfoResult{
  kImportedInfo info;
  kQuasiArchiveContent *content;
};

typedef void (*kProgress)(int porogress, const QString&text = QString::null);

typedef QList<kPlugin*> kPluginList;

typedef enum kPluginBaseType {plugInputBasic, plugInputArch, plugOutput};


typedef struct kNode
{
  QString name;
  bool isDir;
//  struct kNode * owner;
  QString data;
};

typedef enum kNodeDataType{
  nodeDesc,
  nodeThumb,
  nodeIcon
};

typedef QList<kNode*> kNodes;

class kVersion{
  private:
    QString _author;
    QString _description;
    QString _name;
    int _version;
  public:
    kVersion(int version = 0, const QString &name = QString::null, const QString &description = QString::null, const QString &author = QString::null) 
            { _version = version; _name = name; _author = author; _description = description; } ;
    int version(){ return _version; };
    QString & author() { return _author; };
    QString & description() { return _description; };
    QString & name() { return _name; };
};

class kPlugin: public QObject, public kVersion
{
  Q_OBJECT
  public:
    kPlugin(int version = 0, const QString &name = QString::null, const QString &description = QString::null);
    virtual kPluginBaseType baseType() = 0;
};

class kInputPlugin: public kPlugin
{
  Q_OBJECT
  public:
    kInputPlugin(int version = 0, const QString &name = QString::null, const QString &description = QString::null);
    virtual kDetectInfo * getDetect() = 0;
    virtual bool canYouHandle(kFileInfo*fi);
    virtual ~kInputPlugin();
};

class kInputBasic: public kInputPlugin
{
  Q_OBJECT
  public:
    kInputBasic(int version = 0, const QString &name = QString::null, const QString &description = QString::null);
    kPluginBaseType baseType(){ return plugInputBasic; };
    virtual int getType();
    virtual int getFileInfo(kFileInfo *f, kInfoResult&result);
};

class kInputArchive: public kInputPlugin
{
  Q_OBJECT
  public:
    kInputArchive(int version = 0, const QString &name = QString::null, const QString &description = QString::null);
    kPluginBaseType baseType(){ return plugInputArch; };

};


class kOutputPlugin: public kPlugin
{
  Q_OBJECT
  public:
    kOutputPlugin(int version = 0, const QString &name = QString::null, const QString &description = QString::null);
};

class kOutputBasic: public kOutputPlugin
{
  Q_OBJECT
  public:
    kOutputBasic(int version = 0, const QString &name = QString::null, const QString &description = QString::null);
    virtual ~kOutputBasic(){};
    kPluginBaseType baseType(){ return plugOutput; };
    virtual kNode * createNode(QFileInfo*fi) {};
    virtual kNode * createNode(kNode*parent, const kBasicFileInfo * info) {};
    virtual void freeNode(kNode*node){};
    virtual void freeNodes(kNodes*nodes){};
    virtual int addNodeData(kNode * node, const kBasicFileInfo * info){};
    virtual kNodes * subNodes(kNode*node) {};
    virtual int sync(){};
    virtual int setCatalogFileName(const QString&fileName){};
    virtual kNode * rootNode(){};
};

class kModule: public QObject, public kVersion
{
  Q_OBJECT
  private:
     kPluginList _plugins;
  public:
    kModule(int version = 0, const QString &name = QString::null, const QString &author = QString::null, const QString &description = QString::null);
    ~kModule();
    kPluginList * plugins();
    int addPlugin(kPlugin*p);
    int count();
    int delPlugin(int idx);
    kPlugin * plugin(int idx);
};

#endif // _KMODULE_H_

